package 初级算法;

/**
 * @Author cheng.song
 * @create 2021/11/9 10:13
 */
public class 买卖股票的最佳时机2 {
    public static void main(String[] args) {
        int[] is = {7,1,5,3,6,4};
        System.out.println(maxProfit(is));
    }
    public static int maxProfit(int[] prices) {
        int total = 0;
        for (int i = 0; i < prices.length-1; i++) {
            total += Math.max(prices[i + 1] - prices[i], 0);
        }
        return total;
    }
}

